package regularexpression;

import java.time.chrono.ThaiBuddhistEra;
import java.util.Scanner;
import java.util.regex.Pattern;

public class RegularExpression {
    private String ID;
    private String password;
    private String passwordReconfirm;
    private String email;

    public String getID() {
        return ID;
    }

    public String getPassword() {
        return password;
    }

    public String getEmail() {
        return email;
    }

    public void setID(String ID) {
        this.ID = ID;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public void setPasswordReconfirm(String passwordReconfirm) {
        this.passwordReconfirm = passwordReconfirm;
    }

    public static void main(String[] args) {
        RegularExpression regularExpression = new RegularExpression();
        regularExpression.register();
    }

    public void register() {
        Pattern patternId = Pattern.compile("^[a-zA-Z]\\w{5,17}$");  //输入用户名，要求6-20位字母、数字、下划线组成
        Pattern patternPassword = Pattern.compile("^(?=.*\\d)(?=.*[a-z])(?=.*[A-Z])[a-zA-Z0-9]{6,}$");  //输入密码，要求(必须包含大小写字母和数字的组合，不能使用特殊字符，长度不少于6位）
        Pattern patternEmail = Pattern.compile("^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$");

        Scanner sc = new Scanner(System.in);
        System.out.println("请输入ID");
        //ID的正则判断,输入用户名，要求6-20位字母、数字、下划线组成
        while (true) {
            ID = sc.next();
            if (patternId.matcher(ID).matches()) {
                System.out.println("账户创建成功,请继续输入密码");
                this.ID = ID;
                break;
            } else {
                System.out.println("账户输入不符合要求，请继续输入");
                continue;
            }
        }

        //密码的正则判断,输入密码，要求(必须包含大小写字母和数字的组合，不能使用特殊字符，长度不少于6位）
        while (true) {
            password = sc.next();
            if (patternPassword.matcher(password).matches()) {
                System.out.println("创建密码格式正确，请再次确认密码");
                this.password = password;
                break;
            } else {
                System.out.println("密码格式错误，请重新输入");
                continue;
            }
        }

        //确认密码
        while (true) {
            passwordReconfirm = sc.next();
            if (passwordReconfirm.equals(password)) {
                System.out.println("密码创建成功，请输入您的邮箱");
                break;
            } else {
                System.out.println("您此次输入的密码与上一次不同，请重新输入");
                continue;
            }
        }

        //创建邮箱
        while (true) {
            email = sc.next();
            if (patternEmail.matcher(email).matches()) {
                this.email = email;
                System.out.println("邮箱格式正确,创建账户成功");
                break;
            } else {
                System.out.println("邮箱格式错误，请重新输入");
                continue;
            }
        }
    }

}



